import { request } from "@/utils/request";
import ApiResult from "@/api/base/ApiResult";
import {
  templateQueryReq,
  templateSaveReq,
  templateDetailReq,
  templateDelReq, 
  IActivityByType, 
  IActPrizeByPageArea,
  IActivityCouponDefineInfo,
} from "@/api/modules/activity";

/**
 * 分页获取模板标签信息
 * @returns {promise} Promise
 */
export async function getLabelPagerApi(data: any) {
  const rs: ApiResult<any> = await request(
    "activity/template/getLabelPager",
    data
  );
  return rs;
}

/**
 * 分页获取模板样式信息
 * @returns {promise} Promise
 */
export async function templatePatternPageApi(data: templateQueryReq) {
  const rs: ApiResult<any> = await request(
    "activity/template/templatePatternPage",
    data
  );
  return rs;
}

/**
 * 新增/编辑模板样式信息
 * @returns {promise} Promise
 */
export async function editTemplatePatternApi(data: templateSaveReq) {
  const rs: ApiResult<any> = await request(
    "activity/template/editTemplatePattern",
    data
  );
  return rs;
}

/**
 * 根据id获取模板样式信息
 * @returns {promise} Promise
 */
export async function getTemplatePatternApi(data: templateDetailReq) {
  const rs: ApiResult<any> = await request(
    "activity/template/getTemplatePattern",
    data
  );
  return rs;
}

/**
 * 删除/批量删除模板
 * @returns {promise} Promise
 */
export async function delTemplateApi(data: templateDelReq) {
  const rs: ApiResult<any> = await request(
    "activity/template/delTemplate",
    data
  );
  return rs;
}

/**
 * 分页获取活动信息
 * @returns {promise} Promise
 */
export async function activityPageApi(data: any) {
  const rs: ApiResult<any> = await request("activity/actPager", data);
  return rs;
}

/**
 * 新增活动
 * @returns {promise} Promise
 */
export async function addActApi(data: any) {
  const rs: ApiResult<any> = await request("activity/addAct", data);
  return rs;
}

/**
 * 新增活动——预扣库存
 * @returns {promise} Promise
 */
export async function addActivityApi(data: any) {
  const rs: ApiResult<any> = await request("activity/addActivity", data);
  return rs;
}

/**
 * 编辑活动
 * @returns {promise} Promise
 */
export async function editActApi(data: any) {
  const rs: ApiResult<any> = await request("activity/editActivity", data);
  return rs;
}

/**
 * 根据id获取活动详情
 * @returns {promise} Promise
 */
export async function getActivityByIdApi(data: any) {
  const rs: ApiResult<any> = await request("activity/actInfo", data);
  return rs;
}

/**
 * 删除/批量删除
 * @returns {promise} Promise
 */
export async function delActivityByIdApi(data: any) {
  const rs: ApiResult<any> = await request("activity/dels", data);
  return rs;
}

/**
 * 获取商家列表
 * @returns {promise} Promise
 */
export async function getListStoreApi() {
  const rs: ApiResult<any> = await request("activity/ext/getStores", {});
  return rs;
}
/**
 * 获取商家列表2
 * @returns {promise} Promise
 */
export async function getListStoreApi2(data:any) {
  const rs: ApiResult<any> = await request("activity/ext/getStores", data);
  return rs;
}
/**
 * 商户商品分类
 * @returns {promise} Promise
 */
export async function getGoodsCategory(data:any) {
  const rs: ApiResult<any> = await request("activity/ext/getGoodsCategory", data);
  return rs;
}

/**
 * 获取商品列表
 * @returns {promise} Promise
 */
export async function getProductListApi(data: any) {
  const rs: ApiResult<any> = await request("activity/ext/getProductList", data);
  return rs;
}

/**
 * 获取商品详情
 * @returns {promise} Promise
 */
export async function getProductDetailApi(data: any) {
  const rs: ApiResult<any> = await request(
    "activity/ext/getProductDetail",
    data
  );
  return rs;
}

/**
 * 获取规格列表
 * @returns {promise} Promise
 */
export async function getSpesApi(data: any) {
  const rs: ApiResult<any> = await request("activity/ext/getSpes", data);
  return rs;
}

/**
 * 获取规格详情
 * @returns {promise} Promise
 */
export async function getSpeInfoApi(data: any) {
  const rs: ApiResult<any> = await request("activity/ext/getSpeInfo", data);
  return rs;
}

// 获取卡券批次详情
export function getCouponSpecDetail(data: {id: string | number}) {
  return request('activity/ext/getCouponBatchInfo', data)
}

/**
 * 编辑活动奖品
 * @returns {promise} Promise
 */
export async function editActPrizeApi(data: any) {
  const rs: ApiResult<any> = await request("activity/editActPrize", data);
  return rs;
}

/**
 * 修改活动上下线状态
 * @returns {promise} Promise
 */
export async function updActivityStatusApi(data: any) {
  const rs: ApiResult<any> = await request("activity/updActStatus", data);
  return rs;
}

/**
 * 分页获取客群
 * @returns {promise} Promise
 */
export async function getUserGroupPagerApi(data: any) {
  const rs: ApiResult<any> = await request(
    "activity/ext/getUserGroupPager",
    data
  );
  return rs;
}

/**
 * 获取活动已选黑白名单对应的名称
 * @returns {promise} Promise
 */
export async function getExistUserGroupApi(data: any) {
  const rs: ApiResult<any> = await request(
    "activity/ext/getExistUserGroup",
    data
  );
  return rs;
}

/**
 * 长链转短链
 * @returns {promise} Promise
 */
export async function changeUrlApi(data: any) {
  const rs: ApiResult<any> = await request("activity/changeUrl", data);
  return rs;
}

/**
 * 机构列表
 * @returns {promise} Promise
 */
export async function authInsApi(data: any) {
  const rs: ApiResult<any> = await request(
    "merchant/merchantIns/authIns",
    data
  );
  return rs;
}

/**
 * 获取商户可用的代币列表
 * @returns {promise} Promise
 */
export async function getCurrencysApi(data: any) {
  const rs: ApiResult<any> = await request(
    "extensions/currency/manage/getCurrencys",
    data
  );
  return rs;
}

/**
 * 获取任务类型
 * @returns {promise} Promise
 */
export async function getTaskListApi(data: any) {
  const rs: ApiResult<any> = await request(
    "activity/taskConfig/taskList",
    data
  );
  return rs;
}

/**
 * 新增任务活动配置
 * @returns {promise} Promise
 */
export async function addTaskActApi(data: any) {
  const rs: ApiResult<any> = await request("activity/taskConfig/add", data);
  return rs;
}

/**
 * 获取活动区域信息
 * @returns {promise} Promise
 */
export async function getActPageFlagsApi(data: any) {
  const rs: ApiResult<any> = await request("activity/getActPageFlags", data);
  return rs;
}

/**
 * 新增/修改 模板类型
 * @returns {promise} Promise
 */
export async function saveOrUpdateTemplateTypeApi(data: any) {
  const rs: ApiResult<any> = await request(
    "merchant/custom/activityTemplate/saveOrUpdateType",
    data
  );
  return rs;
}

/**
 * 分页获取模板类型列表
 * @returns {promise} Promise
 */
export async function pageOfTemplateTypeApi(data: any) {
  const rs: ApiResult<any> = await request(
    "merchant/custom/activityTemplate/pageOfTemplateType",
    data
  );
  return rs;
}

/**
 * 删除模板类型
 * @returns {promise} Promise
 */
export async function delTemplateTypeApi(data: any) {
  const rs: ApiResult<any> = await request(
    "merchant/custom/activityTemplate/delTemplateType",
    data
  );
  return rs;
}

/**
 * 分页获取自建模板列表
 * @returns {promise} Promise
 */
export async function pageOfTemplateApi(data: any) {
  const rs: ApiResult<any> = await request(
    "merchant/custom/activityTemplate/pageOfTemplate",
    data
  );
  return rs;
}


/**
 * 新增/修改 登录页
 * @returns {promise} Promise
 */
export async function saveOrUpdateLoginTemplateApi(data: any) {
  const rs: ApiResult<any> = await request(
    "merchant/loginStyle/saveOrUpdate",
    data
  );
  return rs;
}

/**
 * 删除 登录页
 * @returns {promise} Promise
 */
export async function delLoginTemplateApi(data: any) {
  const rs: ApiResult<any> = await request(
    "merchant/loginStyle/del",
    data
  );
  return rs;
}

/**
 * 详情 登录页
 * @returns {promise} Promise
 */
export async function detailLoginTemplateApi(data: any) {
  const rs: ApiResult<any> = await request(
    "merchant/loginStyle/info",
    data
  );
  return rs;
}

/**
 * 新增/修改 自建模板
 * @returns {promise} Promise
 */
export async function saveOrUpdateTemplateApi(data: any) {
  const rs: ApiResult<any> = await request(
    "merchant/custom/activityTemplate/saveOrUpdateTemplate",
    data
  );
  return rs;
}

/**
 * 删除自建模板
 * @returns {promise} Promise
 */
export async function delActivityTemplateApi(data: any) {
  const rs: ApiResult<any> = await request(
    "merchant/custom/activityTemplate/delTemplate",
    data
  );
  return rs;
}

/**
 * 获取自建模板详情
 * @returns {promise} Promise
 */
export async function getTemplateInfoApi(data: any) {
  const rs: ApiResult<any> = await request(
    "merchant/custom/activityTemplate/getTemplateInfo",
    data
  );
  return rs;
}

/**
 * 获取活动提示语
 * @returns {promise} Promise
 */
export async function queryActHintListApi(data: any) {
  const rs: ApiResult<any> = await request("activity/actHint/queryList", data);
  return rs;
}

/**
 * 保存活动提示语
 * @returns {promise} Promise
 */
export async function saveHintMsgApi(data: any) {
  const rs: ApiResult<any> = await request(
    "activity/actHint/saveHintMsg",
    data
  );
  return rs;
}

/**
 * 新增/编辑活动基本信息
 * @returns {promise} Promise
 */
export async function editActBaseInfoApi(data: any) {
  const rs: ApiResult<any> = await request("activity/editActBaseInfo", data);
  return rs;
}

/**
 * 新增/编辑页面配置
 * @returns {promise} Promise
 */
export async function editActPageApi(data: any) {
  const rs: ApiResult<any> = await request("activity/editActPage", data);
  return rs;
}

/**
 * 新增/编辑页面区域配置
 * @returns {promise} Promise
 */
export async function addPageAreaApi(data: any) {
  const rs: ApiResult<any> = await request("activity/editPageArea", data);
  return rs;
}

/**
 * 根据活动id获取活动基本信息+页面配置信息
 * @returns {promise} Promise
 */
export async function getActBaseInfoApi(data: any) {
  const rs: ApiResult<any> = await request("activity/getActBaseInfo", data);
  return rs;
}

/**
 * 根据页面区域标识和活动id获取页面区域信息
 * @returns {promise} Promise
 */
export async function getPageAreaApi(data: any) {
  const rs: ApiResult<any> = await request("activity/getPageArea", data);
  return rs;
}

/**
 * 奖品管理-根据活动id获取页面区域及相关奖池、奖品
 * @returns {promise} Promise
 */
export async function pageAreaPrizeApi(data: any) {
  const rs: ApiResult<any> = await request("activity/pageAreaPrize", data);
  return rs;
}

/**
 * 奖品管理-删除奖品池
 * @returns {promise} Promise
 */
export async function delPrizeAreaApi(data: any) {
  const rs: ApiResult<any> = await request("activity/delPrizeArea", data);
  return rs;
}

/**
 * 奖品管理-新增/编辑奖品池(编辑时，不包含奖品操作)
 * @returns {promise} Promise
 */
export async function editPrizeAreaApi(data: any) {
  const rs: ApiResult<any> = await request("activity/editPrizeArea", data);
  return rs;
}

/**
 * 奖品管理-奖品上下架
 * @returns {promise} Promise
 */
export async function prizeOnlineApi(data: any) {
  const rs: ApiResult<any> = await request("activity/prizeOnline", data);
  return rs;
}

/**
 * 奖品管理-奖品规格上下架
 * @returns {promise} Promise
 */
export async function prizeSpeOnlineApi(data: any) {
  const rs: ApiResult<any> = await request("activity/prizeSpeOnline", data);
  return rs;
}

/**
 * 奖品管理-新增奖品
 * @returns {promise} Promise
 */
export async function addPrizeApi(data: any) {
  const rs: ApiResult<any> = await request("activity/addPrize", data);
  return rs;
}

/**
 * 奖品管理-删除奖品
 * @returns {promise} Promise
 */
export async function delPrizeApi(data: any) {
  const rs: ApiResult<any> = await request("activity/delPrize", data);
  return rs;
}

/**
 * 奖品管理-编辑奖品
 * @returns {promise} Promise
 */
export async function updPrizeApi(data: any) {
  const rs: ApiResult<any> = await request("activity/updPrize", data);
  return rs;
}

/**
 * 奖品管理-奖品规格库存编辑
 * @returns {promise} Promise
 */
export async function editPrizeSpeStockApi(data: any) {
  const rs: ApiResult<any> = await request("activity/editPrizeSpeStock", data);
  return rs;
}

/**
 * 奖品管理-编辑规格(只编辑信息，不编辑库存及状态)
 * @returns {promise} Promise
 */
export async function editPrizeSpeApi(data: any) {
  const rs: ApiResult<any> = await request("activity/editPrizeSpe", data);
  return rs;
}

/**
 * 奖品管理-新增规格-积分和商品
 * @returns {promise} Promise
 */
export async function addPrizeSpeApi(data: any) {
  const rs: ApiResult<any> = await request("activity/addPrizeSpe", data);
  return rs;
}

/**
 * 奖品管理-新增规格-礼品包
 * @returns {promise} Promise
 */
export async function addPackPrizeSpeApi(data: any) {
  const rs: ApiResult<any> = await request("activity/addPackPrizeSpe", data);
  return rs;
}

/**
 * 查询题库分组树
 * @returns {promise} Promise
 */
export async function queryQuestionGroupTreeApi(data: any) {
  const rs: ApiResult<any> = await request(
    "activity/questionGroup/queryGroupTree",
    data
  );
  return rs;
}

/**
 * 保存题库分组
 * @returns {promise} Promise
 */
export async function saveQuestionGroupApi(data: any) {
  const rs: ApiResult<any> = await request(
    "activity/questionGroup/saveGroup",
    data
  );
  return rs;
}

/**
 * 删除题库分组
 * @returns {promise} Promise
 */
export async function delQuestionGroupApi(data: any) {
  const rs: ApiResult<any> = await request(
    "activity/questionGroup/delGroup",
    data
  );
  return rs;
}

/**
 * 题库上传
 * @returns {promise} Promise
 */
export async function updloadQuestionApi(data: any) {
  const rs: ApiResult<any> = await request("activity/question/upload", data);
  return rs;
}

/**
 * 删除题目
 * @returns {promise} Promise
 */
export async function delQuestionApi(data: any) {
  const rs: ApiResult<any> = await request("activity/question/del", data);
  return rs;
}

/**
 * 题目更新
 * @returns {promise} Promise
 */
export async function updateQuestionApi(data: any) {
  const rs: ApiResult<any> = await request("activity/question/update", data);
  return rs;
}

/**
 * 活动审核
 * @returns {promise} Promise
 */
export async function applyInfoEntityApi(data: any) {
  const rs: ApiResult<any> = await request(
    "merchant/applyInfoEntity/saveOrUpdate",
    data
  );
  return rs;
}

/**
 * 批量移动题目
 * @returns {promise} Promise
 */
export async function questionMoveApi(data: any) {
  const rs: ApiResult<any> = await request("activity/question/move", data);
  return rs;
}

/**
 * 修改投票作品状态
 * @returns {promise} Promise
 */
export async function voteWorksUpdateStatusApi(data: any) {
  const rs: ApiResult<any> = await request(
    "activity/voteWorks/updateStatus",
    data
  );
  return rs;
}

/**
 * 新增投票作品
 * @returns {promise} Promise
 */
export async function voteWorksAddApi(data: any) {
  const rs: ApiResult<any> = await request("activity/voteWorks/addNew", data);
  return rs;
}

/**
 * 更新投票作品
 * @returns {promise} Promise
 */
export async function voteWorksUpdateApi(data: any) {
  const rs: ApiResult<any> = await request("activity/voteWorks/updateWorks", data);
  return rs;
}

/**
 * 报名活动详情
 * @returns {promise} Promise
 */
export async function getEntryRecordPager(data: any) {
  const rs: ApiResult<any> = await request("activity/entryRecordPager", data);
  return rs;
}

/**
 * 奖品管理-删除奖品规格（要判断是否被引用）
 * @returns {promise} Promise
 */
export async function delPrizeSpesApi(data: any) {
  const rs: ApiResult<any> = await request("activity/delPrizeSpes", data);
  return rs;
}

/**
 * 发放门票
 * @returns {promise} Promise
 */
export async function distributeTicket(data: any) {
  const rs: ApiResult<any> = await request("activity/distributeTicket", data);
  return rs;
}

/**
 * 组件-新增/编辑
 * @returns {promise} Promise
 */
export async function componentEditApi(data: any) {
  const rs: ApiResult<any> = await request("merchant/component/edit", data);
  return rs;
}

/**
 * 组件-分页查询
 * @returns {promise} Promise
 */
export async function componentPagerApi(data: any) {
  const rs: ApiResult<any> = await request("merchant/component/componentPager", data);
  return rs;
}

/**
 * 组件-删除/批量删除
 * @returns {promise} Promise
 */
export async function componentDelApi(data: any) {
  const rs: ApiResult<any> = await request("merchant/component/del", data);
  return rs;
}

/**
 * 组件-移动/批量移动
 * @returns {promise} Promise
 */
export async function componentMoveApi(data: any) {
  const rs: ApiResult<any> = await request("merchant/component/move", data);
  return rs;
}

/**
 * 组件分类-分页查询
 * @returns {promise} Promise
 */
export async function componentGroupApi(data: any) {
  const rs: ApiResult<any> = await request("merchant/component/categoryPager", data);
  return rs;
}

/**
 * 组件分类-新增/编辑
 * @returns {promise} Promise
 */
export async function componentGroupAddApi(data: any) {
  const rs: ApiResult<any> = await request("merchant/component/categoryEdit", data);
  return rs;
}

/**
 * 组件分类-删除
 * @returns {promise} Promise
 */
export async function componentGroupDelApi(data: any) {
  const rs: ApiResult<any> = await request("merchant/component/categoryDel", data);
  return rs;
}

/**
 * 活动预览
 * @returns {promise} Promise
 */
export async function activityPreview(data: any) {
  const rs: ApiResult<any> = await request("activity/preview", data);
  return rs;
}

/**
 * 根据页面区获类型的取不同类型的活动列表
 * @param data
 */
export function getActsByType(data: {type: number}): Promise<ApiResult<IActivityByType[]>> { // type => 8: secKill
  return request('activity/getActsByType', data);
}

/**
 * 获取PageArea下的商品
 * @param data
 */
export function getActPrizeList(data: {pageFlag: string, actId: number}): Promise<ApiResult<IActPrizeByPageArea[]>> {
  return request('activity/prize/list', data)
}

export function getActSecKillConfig(data: {actId: number, pageFlag: string}): Promise<ApiResult<any>> {
  return request('business/actSeckillConfig', data)
}

/**
 * 批量更新奖品号
 * @param data
 */
export function updPrizeSorted(data: {prizeSorteds: {id: number, sorted: number}[]}):Promise<ApiResult<any>> {
  return request("activity/updPrizeSorted", data)
}

/**
 * 获取活动通知配置的系统通知人
 * @param data
 */
export function getSystemNoticeUser(data: {id:string|number}):Promise<ApiResult<any>> {
  return request("activity/notice/queryMerchantInfos", data)
}

/**
 * 获取单个活动通知配置
 * @param data
 */
export function getActNoticeConfig(data: {configId?:string|number, actId:number|string}):Promise<ApiResult<any>> {
  return request("/activity/notice/queryConfig ", data)
}
/**
 * 保存单个活动通知配置
 * @param data
 */
export function saveActNoticeConfig(data: {actId:string|number, noticeType:1|0, noticeUserIds?:string, noticePhones?:string, noticeWebhookUrls?:string}):Promise<ApiResult<any>> {
  return request("/activity/notice/saveOrUpdateConfig  ", data)
}


/** 选择客群
 * @param data
 */
export function userGroupListApi(data:any):Promise<ApiResult<any>> {
  return request("user/userGroup/userGroupList", data)
}

/**
 * 预上线选择客群
 * @param data
 */
export function preOnlineApi(data:any):Promise<ApiResult<any>> {
  return request("activity/preOnline", data)
}

/**
 * 获取活动优惠券 详情
 */
export function getCouponDefineInfo(data: {id: number | string}):Promise<ApiResult<IActivityCouponDefineInfo>> {
  return request('activity/ext/getCouponDefineDetail', data)
}

/**
 * 根据活动id获取最新的活动审核信息
 * @param data
 */
export function actApplyInfo(data:any):Promise<ApiResult<any>> {
  return request("merchant/applyInfoEntity/actApplyInfo", data)
}
